set(COMPONENT_NAME "FMU3cs_crane")
set(COMPONENT_MAIN_DIR "${DEMO_FMU_MAIN_DIR}")
set(COMPONENT_SOURCES craneFMU.h craneFMU.cpp)
set(COMPONENT_RESOURCES_DIR "")
if (CH_ENABLE_MODULE_IRRLICHT)
  set(COMPONENT_CHRONO_DEPENDENCIES Chrono_core Chrono_irrlicht)
  if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
    set(COMPONENT_DLL_DEPENDENCIES "${CH_IRRLICHT_DLL}")
  else()
    set(COMPONENT_DLL_DEPENDENCIES "")
  endif()
else()
  set(COMPONENT_CHRONO_DEPENDENCIES Chrono_core)
endif()

set(FMU_CS TRUE)
#set(FMU_TESTING ON)

#--------------------------------------------------------------

# Set include paths, compiler & linker flags, and libraries
list(APPEND LIBS Chrono_core)

include_directories(${FMU_FORGE_DIR})

if(CH_ENABLE_MODULE_IRRLICHT)
  list(APPEND LIBS "Chrono_irrlicht")
endif()

#==============================================================

message(STATUS "...add ${COMPONENT_NAME}")
message(STATUS "   FetchContent(fmu-forge)")

set(FMU_MODEL_IDENTIFIER ${COMPONENT_NAME})
set(USE_CUSTOM_TYPESPLATFORM OFF)
set(FMU_MAIN_DIRECTORY ${COMPONENT_MAIN_DIR})
set(FMU_RESOURCES_DIRECTORY ${COMPONENT_RESOURCES_DIR})
set(FMU_DEPENDENCIES ${COMPONENT_DLL_DEPENDENCIES})
set(FMU_MSG_PREFIX "   - ")

FetchContent_Declare(
    ${FMU_MODEL_IDENTIFIER}
    SOURCE_DIR ${FMU_FORGE_DIR}/fmi3
)

FetchContent_MakeAvailable(${FMU_MODEL_IDENTIFIER})

string(TOUPPER ${FMU_MODEL_IDENTIFIER} FMU_MODEL_IDENTIFIER_UPPERCASE)
MARK_AS_ADVANCED(FETCHCONTENT_BASE_DIR)
MARK_AS_ADVANCED(FETCHCONTENT_FULLY_DISCONNECTED)
MARK_AS_ADVANCED(FETCHCONTENT_QUIET)
MARK_AS_ADVANCED(FETCHCONTENT_SOURCE_DIR_${FMU_MODEL_IDENTIFIER_UPPERCASE})
MARK_AS_ADVANCED(FETCHCONTENT_UPDATES_DISCONNECTED)
MARK_AS_ADVANCED(FETCHCONTENT_UPDATES_DISCONNECTED_${FMU_MODEL_IDENTIFIER_UPPERCASE})

#--------------------------------------------------------------

add_dependencies(${FMU_MODEL_IDENTIFIER} ${COMPONENT_CHRONO_DEPENDENCIES})

# add FMU target
target_sources(${FMU_MODEL_IDENTIFIER} PRIVATE ${COMPONENT_SOURCES})

target_link_libraries(${FMU_MODEL_IDENTIFIER} ${LIBS})

if(MSVC)
  set_target_properties(${FMU_MODEL_IDENTIFIER} PROPERTIES MSVC_RUNTIME_LIBRARY ${CH_MSVC_RUNTIME_LIBRARY})
endif()

#--------------------------------------------------------------

set(CRANE_FMU3_MODEL_IDENTIFIER ${FMU_MODEL_IDENTIFIER} PARENT_SCOPE)
set(CRANE_FMU3_DIRECTORY ${FMU_DIRECTORY} PARENT_SCOPE)
set(CRANE_FMU3_FILENAME ${FMU_FILENAME} PARENT_SCOPE)
set(CRANE_FMU3_RUNTIME_OUTPUT_DIRECTORY ${FMU_RUNTIME_OUTPUT_DIRECTORY} PARENT_SCOPE)
